package com.tcm.user.authentication;

import com.tcm.user.factory.Signup;
import com.tcm.user.factory.UserFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SignupFactory implements UserFactory {

    private final Logger log = LoggerFactory.getLogger(SignupFactory.class);
    private static final Map<String, Signup> strategyMap = new HashMap<>();
    // 构造函数，如果是集合接口对象，那么会把spring容器中所有关于该接口的子类，全部抓出来放入到集合中
    public SignupFactory(List<Signup> strategyList){
        for (Signup strategy: strategyList) {
            strategyMap.put(strategy.supports(),strategy);
        }
    }

    @Override
    public Signup createInstance(String type){
        Signup strategy = strategyMap.get(type);
        return strategy;
    }
}